Repository navigation
Harden input validation, doc access, and CI - #23
Merged
Merged
Conversation
- CI: add GitHub Actions (lint, typecheck, unit + integration); add typecheck/test:unit/test:integration scripts; fix the 3 tsc errors and 41 ESLint errors that were blocking a green baseline. - Payload caps: bound doc content (1 MB), title, version_note, meta, and comment body/author/anchor_text/anchor_type with 400s instead of unbounded writes. - DB: index the hot read paths (docs userId+updatedAt and visibility+ createdAt, doc_versions docId+versionNumber, comments docId+createdAt and docId+status). - Auth: extract one evaluateDocAccess used by GET /docs/:slug, the feedback endpoints, and the share page, removing three divergent implementations. Fixes magic tokens sent via X-Magic-Token not unlocking owner-only fields on GET. - Security: add HSTS/CSP and related headers (CSP production-only, with the Redoc CDN and Google Fonts allowed for /api-docs). - Tests: cover every doc read access path and the new payload limits.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A hardening pass covering the five items from the repo scan, all in one PR.
1. Green baseline + CI
.github/workflows/ci.yml:lint,typecheck, unit tests, and integration tests against a Postgres service.typecheck,test:unit, andtest:integrationscripts.tscerrors (Prisma JSON input types in test helpers) and all 41 ESLint errors (35jsx-no-comment-textnodes, 6react-hooks/set-state-in-effect).ThemeToggle,useReviewerName, andcreated/[slug]now read browser state viauseSyncExternalStore; the three fetch-on-mount effects keep a scoped, commented disable.2. Payload caps
POST/PATCH /docs: content ≤ 1 MB (UTF-8), title/version_note ≤ 500 chars, meta ≤ 16 KB and must be a JSON object.anchor_typelimited toline|selection.3. Indexes
New migration
20261025120000_add_query_indexesfor:docs(user_id, updated_at)anddocs(visibility, created_at)doc_versions(doc_id, version_number)comments(doc_id, created_at)andcomments(doc_id, status)4. Unified doc access
evaluateDocAccess+ shared request adapter insrc/lib/auth.ts.GET /docs/:slug, the feedback endpoints, and the share page all use it; three divergent implementations removed.X-Magic-Tokennow unlocks owner-only fields (meta,views_count) onGET /docs/:slug, matching the other token sources.doc-access.test.tscovers public, magic token (query/header/cookie), doc API key, share token (both params), account API key, wrong token, and owner-field visibility.5. Security headers
X-Content-Type-Options,X-Frame-Options,Referrer-Policy,Permissions-Policyon all routes.'unsafe-inline'for the theme/bootstrap scripts and Mermaid/Redoc styles, pluscdn.redoc.lyand Google Fonts for/api-docs.Test plan
npm run lint— cleannpm run typecheck— cleannpm run test:unit— 100 passednpm run test:integration— 172 passed (server on :3333, test DB on :5435)npm run build— succeedsprisma migrate diff— no driftNotes
POST /docswith empty content andPATCHwithcontent: ""now return 400 (previously accepted/near-500).